﻿using System;
using System.Linq;
using Wicresoft.EKA.MVCExtensions;
using Wicresoft.EKA.ITSM.Business;
using System.Collections.Generic;

namespace Wicresoft.EKA.ITSM.BusinessImpl
{
    public class SMGXJPlanTask : Base, ISMGXJPlanTask
    {
        protected override void Dispose(bool disposing)
        {
        }

        public string GetTicketID()
        {
            WSGetEntryModel model = new WSGetEntryModel();
            model.ShortDescription = DateTime.Now.ToString();
            var proxy = this.GetARProxy<WSGetEntryModel>();
            proxy.SetEntryByQuery(model, "'Type'=\"XunJianTask\"", BMC.ARSystem.Server.SetEntryByQuery_NoMatchOption.NoAction, BMC.ARSystem.Server.SetEntryByQuery_MultiMatchOption.ModifyFirst);
            var list = proxy.GetListEntry("'Type'=\"XunJianTask\"", new System.Collections.Generic.List<uint>()
                {
                    WSGetEntryModel.CharacterField_ID,
                }).FirstOrDefault().CharacterField.ToString();
            return list;
        }

        public object Create(List<SMGXJPlanTaskModel> modelist)
        {
            try
            {
                var proxy = this.GetARProxy<SMGXJPlanTaskModel>();
                proxy.CreateListEntry(modelist);
                return "Success";
            }
            catch (Exception e)
            {
                throw e;
            }            
        }

        public IEnumerable<SMGXJPlanTaskModel> GetList(string Qual)
        {
            var proxy = this.GetARProxy<SMGXJPlanTaskModel>();
            var list = proxy.GetListEntry(Qual, new List<uint> { 
                SMGXJPlanTaskModel.RcChr_Permission_ID,
                SMGXJPlanTaskModel.RcChr_RuleName_ID,
                SMGXJPlanTaskModel.RcChr_RuleType_ID,
                SMGXJPlanTaskModel.RcChr_RuleValue_ID,
                SMGXJPlanTaskModel.RcChr_Threshold_ID,
                SMGXJPlanTaskModel.RcChr_RuleRequestID_ID,
                SMGXJPlanTaskModel.RcChr_Char01_ID,
                SMGXJPlanTaskModel.RcChr_Char02_ID,
                SMGXJPlanTaskModel.RcChr_Char03_ID,
                SMGXJPlanTaskModel.OcChr_Classification_ID,
                SMGXJPlanTaskModel.OcChr_DeviceName_ID,
                SMGXJPlanTaskModel.OcChr_DiskLable_ID,
                SMGXJPlanTaskModel.OcChr_Hostname_ID,
                SMGXJPlanTaskModel.OcChr_Indicators_ID,
                SMGXJPlanTaskModel.OcChr_IP_ID,
                SMGXJPlanTaskModel.OcChr_Location_ID,
                SMGXJPlanTaskModel.OcChr_MarkAsDelete_ID,
                SMGXJPlanTaskModel.OcChr_ObjectRequestID_ID,
                SMGXJPlanTaskModel.OcChr_SQLVersion_ID,
                SMGXJPlanTaskModel.OcChr_Type_ID,
                SMGXJPlanTaskModel.OcChr_Use_ID,
                SMGXJPlanTaskModel.cChr_Description_ID,
                SMGXJPlanTaskModel.cChr_Jifang_ID,
                SMGXJPlanTaskModel.cChr_jigui_ID,
                SMGXJPlanTaskModel.cChr_louceng_ID,
                SMGXJPlanTaskModel.OcChr_Char032_ID,
                SMGXJPlanTaskModel.RcChr_Char02_ID
            });
            return list;
        }

        public string Modify(SMGXJPlanTaskModel model)
        {
            try
            {
                var proxy = this.GetARProxy<SMGXJPlanTaskModel>();
                proxy.SetEntryByQuery(model, "'Request ID' = \"" + model.RequestID + "\"", BMC.ARSystem.Server.SetEntryByQuery_NoMatchOption.NoAction, BMC.ARSystem.Server.SetEntryByQuery_MultiMatchOption.ModifyFirst);
                return "Success";
            }
            catch (Exception e)
            {
                throw e;
            }

        }
    }
}
